<?php
$AppUI->savePlace();

if (! $canAccess) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
$search_str;
$type;

// To configure an aditional filter to use in the search string
if(isset($_REQUEST['search_string'])){
	$search_str = $_REQUEST['search_string'];
	$AppUI->setState( 'SupIdxWhere', $search_str );
}
else{
	$search_str = $AppUI->getState('SupIdxWhere', '');
}

if(isset($_REQUEST['type'])){
	$type = $_REQUEST['type'];
	$AppUI->setState( 'SupIdxType', $type );
}
else{
	$type = $AppUI->getState('SupIdxType', '');
}

// get type list
require_once(DP_BASE_DIR."/modules/masterdata/mdtype.class.php");
$type_list = arrayMerge( array(''=>$AppUI->_('--Select Type--')), getTypeList($typeSupplier, TRUE));

// setup the title block
$titleBlock = new CTitleBlock( 'Suppliers' );
$titleBlock->show();


?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td class="<?=$tab == 0 ? 'tabon' : 'taboff'?>" style="padding-left: 10px; padding-right: 10px"
		onclick="go('?m=suppliers')"><?=$AppUI->_('Shipper list')?></td>
	<td class="tabox" width="100%">&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="2" class="infopanel">
<tr>
<td>
	<? if ($canEdit) { ?>
	<input type="button" class="button" value="<?=$AppUI->_('New suppliers')?>" onclick="doEditSup(0)"/>
	<? } ?>
</td>
<td width="4px">&nbsp;</td>
<form action="index.php" method="get">
	<td align="right" width="100%" nowrap="nowrap">
		<?=$AppUI->_('Search for')?>&nbsp;
		<input type="hidden" name="m" value="suppliers"/>
	</td>
	<td>
		<input type="text" class="text" name="search_string" value="<?=$search_str?>" />
	</td>
	<td>
		<?= arraySelect($type_list,'type','style="font-size:10px"',$type)?>
	</td>
	<td>
		<input type="image" class="button" src="images/search.gif"/>
	</td>
</form>
<td width="4px">&nbsp;</td>
</tr>
</table>
<table id="idTableMasterdata" class="list" width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>

	<th nowrap="nowrap">&nbsp;</th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Code' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Exact Code' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Name' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Address' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Tel' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Fax' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'VAT Code' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Division' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Delete' );?></th>
</tr>

<?php
// retrieving some dynamic content using an easy database query
// add/show now gradually the einstein quotes
/*
$supplierO = new CSupplier();
$suppliers = $supplierO->loadAll('sup_name',$default_search_string);
*/
$q= new DBQuery();
$q->addTable('suppliers');
$q->addJoin('divisions','','div_id = sup_id');
if($search_str!= null && $search_str != ''){
	$q->addWhere('sup_name like \'%'.$search_str.'%\'');
}
if($type!= null && $type!= ''){
	$q->addWhere('sup_type ='.$type);
}
$q->addOrder('sup_name');
$suppliers = $q->loadList();
if (empty($suppliers)) {?>
<tr class="second">
<td colspan="100"><?php echo $AppUI->_( 'No item available' );?></td>
</tr>
<?php
}
$i = 0;
foreach ($suppliers as $row) {		//parse the array of einstein quotes
	$i++;
?>
<tr class="<?=($i % 2 == 0) ? "second" : "first" ?>">
	<td nowrap="nowrap" width="20">


	<?php if ($canEdit) {	// in case of writePermission on the module show an icon providing edit functionality for the given quote item

		echo "\n".'<a onclick="doEditSup('.$row["sup_id"]. ')">';
		echo dPshowImage( 'images/edit.gif' );
		echo "\n</a>";
	}
	?>
	</td>
	<td> <?php echo $row["sup_code"];?></td>
	<td> <?php echo $row["sup_exact_code"];?></td>
	<td><?php echo $row["sup_name"];?></td>
	<td> <?php echo $row["sup_address"];?></td>
	<td><?php echo $row["sup_tel"];?></td>
	<td> <?php echo $row["sup_fax"];?></td>
	<td> <?php echo $row["sup_vat_code"];?></td>
	<td> <?php echo $row["div_name"];?></td>
	<td>
	<?php if ($canEdit) {
		showIconLink('images/delete.gif', 'js:doDelete('.$row["sup_id"]. ', \''.addslashes($row["sup_name"]).'\')', 'Delete');
	}
	?>
	</td>
</tr>
<?php
}
?>
</tbody>
</table>
<div id="idSupDialog" class="popup" style="visibility: hidden; left: 436px; top: 94.5px; display: none;">
</div>
<script type="text/javascript" language="javascript">
	Table("idTableMasterdata").setNormalHover(1);
</script>
<form name="MdFormDelete" id="MdFormDelete" action="?m=suppliers" method="post">
	<input type="hidden" name="dosql" value ="do_delete" />
	<input type="hidden" id="del_cc_id" name="sup_id" value ="" />
	<input type="hidden" name="del" value ="" />
</form>